<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
 Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="main-assistant.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b></b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>main-assistant.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		No overview generated for 'main-assistant.js'<BR/><BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="MainAssistant.html">MainAssistant</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="reserved">function</span> MainAssistant(params) {
	<span class="comment">/** this is the creator function for your scene assistant object. It will be passed all the 
	*   additional parameters (after the scene name) that were passed to pushScene. The reference
	*   to the scene controller (this.controller) has not be established yet, so any initialization
	*   that needs the scene controller should be done in the setup function below.
	*/</span>
	  <span class="reserved">this</span>.username = params.username;
	  <span class="reserved">this</span>.password = params.password;
}

<span class="comment">/** this function is for setup tasks that have to happen when the scene is first created 
*/</span>
MainAssistant.<span class="reserved">prototype</span>.setup = <span class="reserved">function</span>() {
	<span class="reserved">this</span>.controller.get(<span class="literal">'username'</span>).update(<span class="reserved">this</span>.username);
		
	<span class="comment">/** use Mojo.View.render to render view templates and add them to the scene, if needed.
	 */</span>
	
	<span class="comment">/** setup widgets here-
	 * Instantiates UI widgets for login scene. Each widget requires attributes and a model.
	 * These are passed to the widget in a JSON object.
	 */</span>
	<span class="reserved">this</span>.controller.setupWidget(<span class="literal">"starMapButton"</span>,
         <span class="reserved">this</span>.starMapButtonAttributes = {
		 	type: Mojo.Widget.Button
             },
         <span class="reserved">this</span>.starMapButtonModel = {
             label : <span class="literal">"Star Map"</span>,
             disabled: false
         });
		 
	<span class="reserved">this</span>.controller.setupWidget(<span class="literal">"virtualTelescopeButton"</span>,
         <span class="reserved">this</span>.virtualTelescopeButtonAttributes = {
		 	type: Mojo.Widget.Button
             },
         <span class="reserved">this</span>.virtualTelescopeButtonModel = {
             label : <span class="literal">"Virtual Telescope"</span>,
             disabled: false
         });
		 
	<span class="reserved">this</span>.controller.setupWidget(<span class="literal">"satelliteTrackingButton"</span>,
         <span class="reserved">this</span>.satelliteTrackingButtonAttributes = {
		 	type: Mojo.Widget.Button
             },
         <span class="reserved">this</span>.satelliteTrackingButtonModel = {
             label : <span class="literal">"Satellite Tracking"</span>,
             disabled: false
         });
	<span class="reserved">this</span>.findMe();
	
	<span class="comment">/** add event handlers to listen to events from widgets
	 */</span>
	<span class="reserved">this</span>.starMapButtonHandler = <span class="reserved">this</span>.starMapButton.bindAsEventListener(<span class="reserved">this</span>);
	<span class="reserved">this</span>.virtualTelescopeButtonHandler = <span class="reserved">this</span>.virtualTelescopeButton.bindAsEventListener(<span class="reserved">this</span>);
	<span class="reserved">this</span>.satelliteTrackingButtonHandler = <span class="reserved">this</span>.satelliteTrackingButton.bindAsEventListener(<span class="reserved">this</span>);
}
<span class="comment">/**This is the listener function for the buttons on the main page.  When a button
 *is clicked the appropriate sub-routine is called
 *<span class="attrib">@param</span> event
 **/</span>
MainAssistant.<span class="reserved">prototype</span>.activate = <span class="reserved">function</span>(event) {
	<span class="comment">/** put in event handlers here that should only be in effect when this scene is active. For
	 * example, key handlers that are observing the document
	 * When the scene is activated, start the event listeners for taps on the 
	 * 'Star Map', 'Virtual Telescope', and 'Satellite Tracking' buttons.
	 */</span>
	  Mojo.Event.listen(<span class="reserved">this</span>.controller.get(<span class="literal">'starMapButton'</span>),Mojo.Event.tap,<span class="reserved">this</span>.starMapButtonHandler);
	  Mojo.Event.listen(<span class="reserved">this</span>.controller.get(<span class="literal">'virtualTelescopeButton'</span>),Mojo.Event.tap,<span class="reserved">this</span>.virtualTelescopeButtonHandler);
	  Mojo.Event.listen(<span class="reserved">this</span>.controller.get(<span class="literal">'satelliteTrackingButton'</span>),Mojo.Event.tap,<span class="reserved">this</span>.satelliteTrackingButtonHandler);
}

<span class="comment">/** remove any event handlers you added in activate and do any other cleanup that should happen before
	  * this scene is popped or another scene is pushed on top
	  */</span>
MainAssistant.<span class="reserved">prototype</span>.deactivate = <span class="reserved">function</span>(event) {
	
	  Mojo.Event.stopListening(<span class="reserved">this</span>.controller.get(<span class="literal">'starMapButton'</span>),Mojo.Event.tap,<span class="reserved">this</span>.starMapButtonHandler);
	  Mojo.Event.stopListening(<span class="reserved">this</span>.controller.get(<span class="literal">'virtualTelescopeButton'</span>),Mojo.Event.tap,<span class="reserved">this</span>.virtualTelescopeButtonHandler);
	  Mojo.Event.stopListening(<span class="reserved">this</span>.controller.get(<span class="literal">'satelliteTrackingButton'</span>),Mojo.Event.tap,<span class="reserved">this</span>.satelliteTrackingButtonHandler);
}

<span class="comment">/** this function should do any cleanup needed before the scene is destroyed as 
	 *  a result of being popped off the scene stack
	 */</span>
MainAssistant.<span class="reserved">prototype</span>.cleanup = <span class="reserved">function</span>(event) {
	
}

<span class="comment">/** This function is called when the starmap button is pressed. It pushes the starmap scene
 * onto the scene stack.
 */</span>
MainAssistant.<span class="reserved">prototype</span>.starMapButton = <span class="reserved">function</span>(event) {
	<span class="reserved">if</span> (!event)
		<span class="reserved">return</span>;
	<span class="reserved">this</span>.controller.stageController.pushScene(<span class="literal">'starmap'</span>, event);
}

<span class="comment">/** This function is called when the virtual telescope button is pressed.
 * It pushes the virtual telescope scene onto the scene stack.
 */</span>
MainAssistant.<span class="reserved">prototype</span>.virtualTelescopeButton = <span class="reserved">function</span>(event) {
	<span class="reserved">if</span> (!event)
		<span class="reserved">return</span>;
	<span class="reserved">this</span>.controller.stageController.pushScene(<span class="literal">'virtualtelescope'</span>, event);
}

<span class="comment">/** This function is called when the satellite tracking button is pressed.
 * It pushes the satellite tracking scene onto the scene stack.
 */</span>
MainAssistant.<span class="reserved">prototype</span>.satelliteTrackingButton = <span class="reserved">function</span>(event) {
	<span class="reserved">if</span> (!event)
		<span class="reserved">return</span>;
	<span class="reserved">this</span>.controller.stageController.pushScene(<span class="literal">'satellitetracking'</span>, event);
}

<span class="comment">/** This is the callback function for  finding your location.  It call the updateLocation
 *function, or outputs an error message.
 *<span class="attrib">@param</span> data The location data for the current device.
	 *
	 */</span>
MainAssistant.<span class="reserved">prototype</span>.locationCallback = <span class="reserved">function</span>(data) {
	var locationResponse;
	switch (data.errorCode) {
					case 0:
						locationResponse = <span class="literal">"Latitude: "</span> + data.latitude + <span class="literal">"\n"</span> + <span class="literal">"Longitude: "</span> + data.longitude;
						break;
					case 1:
						locationResponse = <span class="literal">"GPS Timeout."</span>;
						break;
					case 2:
						locationResponse = <span class="literal">"Position Unavailable."</span>;
						break;
					case 5:
						locationResponse = <span class="literal">"Location services are turned off."</span>;
						break;					
					default:
						locationResponse = <span class="literal">"Location error: "</span> + data.errorCode;
						break;
				}
				<span class="reserved">if</span> (data.errorCode == 0) {
					<span class="reserved">this</span>.updateLocation(data);
				}
				<span class="reserved">else</span> {
					<span class="reserved">this</span>.controller.showAlertDialog({
				    	title: $L(<span class="literal">"GPS Error"</span>),
				    	message: $L(<span class="literal">'Could not save current location to server.'</span>),
						choices:[{label:$L(<span class="literal">'Ok'</span>)}]
					});
				}
}

<span class="comment">/** This function actually queries the palm server for current position and then
 * sends that data to locationCallback, a callback function.
 */</span>
MainAssistant.<span class="reserved">prototype</span>.findMe = <span class="reserved">function</span>(event) {
	<span class="reserved">this</span>.controller.serviceRequest(<span class="literal">'palm://com.palm.location'</span>, {
		method:<span class="literal">"getCurrentPosition"</span>,
		parameters:{accuracy: <span class="literal">'Medium'</span>, maximumAge: 10, responseTime: 1},
		onSuccess: <span class="reserved">function</span>( data ) 
			{
				<span class="reserved">this</span>.locationCallback(data);
			}.bind(<span class="reserved">this</span>),
		onFailure: <span class="reserved">function</span>( data )
			{
				<span class="reserved">this</span>.locationCallback(data);
			}.bind(<span class="reserved">this</span>),
		}
	);
}

<span class="comment">/** This function recieves location data, and then makes a remote server call
 * given that data to update the devices current location on the server.
 * <span class="attrib">@param</span> data The current device's location data.
 */</span>
MainAssistant.<span class="reserved">prototype</span>.updateLocation = <span class="reserved">function</span>(data) {    
    var url = <span class="literal">"http://www.bmcstudiosllc.com/starmap/"</span> + <span class="literal">"mobile_update.php"</span>;

    try{
        var request = new Ajax.Request(url,
        {
            method:<span class="literal">'get'</span>,
            parameters: {<span class="literal">'username'</span>: <span class="reserved">this</span>.username, <span class="literal">'password'</span>: <span class="reserved">this</span>.password, <span class="literal">'latitude'</span>: data.latitude, <span class="literal">'longitude'</span>: data.longitude},
            evalJSON:<span class="literal">'true'</span>,
            onComplete: <span class="reserved">this</span>.updateUserCallback.bind(<span class="reserved">this</span>),
        });
    }
    catch (e)
    {
        Mojo.log.error(e);
        <span class="reserved">return</span> 0;
    }
}

<span class="comment">/** Callback function for updateLocation that outputs an error or the recieved data
 * from call to server.
 */</span>
MainAssistant.<span class="reserved">prototype</span>.updateUserCallback = <span class="reserved">function</span>(ajaxResponse) {
	<span class="reserved">if</span> (ajaxResponse.responseJSON.returnCode != 1) {
		Mojo.Controller.errorDialog(ajaxResponse.responseJSON.message);
	}
}
</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b></b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Thu May  6 17:21:45 2010</div>
</body>
</html>
